home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / csr_001.arc / README.C < prev    next >
Text File  |  1988-09-02  |  5KB  |  150 lines

  1. /*
  2. **  R E A D M E . C
  3. **
  4. **  A program to allow quick and easy viewing of a README.DAT text file
  5. **  and to act as a sample program for the C Spot Run C Add-On Library.
  6. **
  7. **  Copyright 1987 Bob Pritchett.   All Rights Reserved.
  8. **
  9. **  History:
  10. **
  11. **  07/09/87 RDP Created for the release of Version 2.1 of C Spot Run.
  12. **
  13. */
  14.  
  15. /*
  16. **  Notes:  Since we only save the cursor once, we know that save_cursor()
  17. **          saves the cursor in pointer 0, thus we needn't save the return
  18. **          value of save_cursor(), and can restore it with restore_cursor(0).
  19. **
  20. **          The variable wmax holds the number of rows in the window, so
  21. **          if the window size is changed, no 'hard wired' integers need to
  22. **          be changed elsewhere in the program.
  23. **
  24. */
  25.  
  26. #include <stdio.h>
  27. #include <ctype.h>
  28. #include <csrmisc.h>
  29. #include <color.h>
  30. #include <skey.h>
  31.  
  32. #define    MAX_LINES    500        /* Maximum Lines in README.DAT */
  33.  
  34. FILE *data;                /* File Pointer to README.DAT */
  35.  
  36. int c;                    /* All Purpose Input Character */
  37. int x;                    /* All Purpose Integer */
  38. int w;                    /* Window for Text */
  39.  
  40. int wmax;                /* Maximum Row in Window */
  41.  
  42. char line[MAX_LINES][80];        /* 500 80 Character Lines */
  43.  
  44. int maxline;                /* Highest Line Number */
  45.  
  46. int curline;                /* Current Line Number */
  47.  
  48. int ol;                    /* Old Line Number */
  49.  
  50. main()                    /* Main Program Entry */
  51.  {
  52.   if ( ! ( data = fopen("README.DAT","r") ) )    /* If Unable to Open File */
  53.    {
  54.     printf("Unable to open README.DAT for reading.\n");    /* Print Message */
  55.     exit(1);                /* Exit with Errorlevel One */
  56.    }
  57.   save_screen();            /* Save the User's Screen */
  58.   save_cursor();            /* Save Cursor Location */
  59.   cursor_off();                /* Turn Off Cursor */
  60.   cls();                /* Clear the Screen */
  61.   wcolor(LGRY_F,WHT_F);            /* Set Colors For Text and Window */
  62.   w = wopen(0,0,20,79,3);        /* Open the Text Window */
  63.   wmax = wrow(w) + 1;            /* See Notes */
  64.   wtitle(w,"╡ README.DAT ╞",1);        /* Title Window */
  65.   maxline = 0;                /* Initialize Maximum Line Count */
  66.   while ( fgets(line[maxline],79,data) )/* While We Can Read Data */
  67.    {
  68.     x = strlen(line[maxline]);        /* Get String Length */
  69.     if ( x )                /* If Positive Length */
  70.     line[maxline][x-1] = 0;        /* Put Null Over NewLine */
  71.     if ( ++maxline == MAX_LINES )    /* If At Maximum Line Number */
  72.        break;                /* Break Out of Loop */
  73.    }
  74.   fclose(data);                /* Close Data File */
  75.   ccenter(22,"Use the Arrow keys, Home, End, PgUp and PgDn.",WHT_F);
  76.   ccenter(24,"Copyright 1987 Bob Pritchett, New Dimension Software.",WHT_F);
  77.   process();                /* Process Commands */
  78.   wclose(w);                /* Good Habit to Close Windows */
  79.   cursor_on();                /* Turn On Cursor */
  80.   restore_cursor(0);            /* We Know Cursor Pointer 0 was Used */
  81.   restore_screen();            /* Restore User's Screen */
  82.  }
  83.  
  84. display()                /* Display Text in Window */
  85.  {
  86.   wcls(w);                /* Clear Window */
  87.   for ( x = curline; x < maxline && ( x - curline ) < wmax; ++x )
  88.       wputat(w,x - curline,0,line[x]);    /* And Display Text */
  89.  }
  90.  
  91. process()                /* Process Input and Display */
  92.  {
  93.   display();                /* Display First Screen of Text */
  94.   while ( 1 )                /* Go Into Perpetual Loop */
  95.    {
  96.     ol = curline;            /* Set Old Line */
  97.     c = getch();            /* Get a Character */
  98.     if ( c == 27 )            /* If it is an ESCape */
  99.        break;                /* Break Out of the Loop */
  100.     else if ( c == 13 )            /* If it is a Carriage Return */
  101.        curline = min(maxline - wmax,curline + wmax);    /* Find New Place */
  102.     else if ( c == 00 )            /* If it is a Null */
  103.      {
  104.       c = getch();            /* Get the Extended Key */
  105.       if ( c == PGUP )            /* If PageUp */
  106.          curline = max(0,curline - wmax);    /* Find New Place */
  107.       else if ( c == PGDN )        /* If PageDown */
  108.          curline = min(maxline - wmax,curline + wmax);    /* Find New Place */
  109.       else if ( c == HOME )        /* If Home */
  110.          curline = 0;            /* Set to Start */
  111.       else if ( c == END )        /* If End */
  112.          curline = max(0,maxline - wmax);    /* Go to Last Page */
  113.       else if ( c == UARROW || c == DARROW )    /* If Single Line Movement */
  114.        {
  115.         if ( c == UARROW )        /* If Up Arrow */
  116.          {
  117.           if ( curline > 0 )        /* If More Text */
  118.            {
  119.             winsert(w,0,1);        /* Insert a Line */
  120.             wputat(w,0,0,line[--curline]);    /* Put Text */
  121.             continue;            /* Continue Loop */
  122.            }
  123.          }
  124.         else if ( c == DARROW )        /* If Down Arrow */
  125.          {
  126.           if ( ( curline + wmax ) < maxline )    /* If More Text */
  127.            {
  128.             ++curline;            /* Increment Current Line */
  129.             wdelete(w,0,1);        /* Delete First Line */
  130.             wputat(w,wmax - 1,0,line[curline + wmax - 1]);  /* Put Text */
  131.             continue;            /* Continue Loop */
  132.            }
  133.          }
  134.        }
  135.       else                /* If Not a Valid Key */
  136.        {
  137.         beep();                /* Beep */
  138.         continue;            /* Continue Loop */
  139.        }
  140.      }
  141.     else                /* If Not a Valid Key */
  142.      {
  143.       beep();                /* Beep */
  144.       continue;                /* Continue Loop */
  145.      }
  146.     if ( ol != curline )        /* If Curline Changed */
  147.        display();            /* Update Display */
  148.    }
  149.  }
  150.